package com.zhuss.order.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.order.order.UpdateOrderBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.OceanException;
import com.zhuss.order.db.dao.ext.OrderDao;
import com.zhuss.order.db.entity.Order;
import com.zhuss.util.JsonUtil;

/**
 * @description: 订单修改
 * @author: zhushanshuo
 * @create: Wed Mar 24 22:32:50 CST 2021
 **/
@Component("orderUpdate")
public class OrderUpdate extends AbstractProcessor<Object, UpdateOrderBo> implements Processor<Object, UpdateOrderBo> {

    @Autowired
    private OrderDao orderDao;
    
    @Autowired
	@Qualifier("orderRead")
	private OrderRead orderRead;
    
    /**
     * 校验
     */
    @Override
    public void check(UpdateOrderBo bo) throws OceanException {
    	// TODO 修改 订单 校验， 请补充
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(UpdateOrderBo param) {
    	Order record = new Order();
    	record.setOrderId(param.getOrderId());
    	record.setOrderNo(param.getOrderNo());
    	record.setOrderSequence(param.getOrderSequence());
    	record.setCompanyId(param.getCompanyId());
    	record.setProductId(param.getProductId());
    	record.setCount(param.getCount());
    	record.setAmount(param.getAmount());
    	record.setComment(param.getComment());
    	record.setStatus(param.getStatus());

    	
    	record.setModifierId(param.getConcurrentUserId());
    	record.setModifier(param.getConcurrentUserName());
    	record.setModifyTime(new Date());
    	orderDao.updateByPrimaryKeySelective(record);
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(UpdateOrderBo param) throws OceanException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.订单模块.key());
    	record.setAction(LogActionEnum.订单修改.key());
    	record.setTargetId(param.getOrderId());
    	record.setTargetName(param.getOrderSequence());
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
